package com.zhou.common.mybatis.template.shiro.config.log;

import com.zhou.common.mybatis.template.shiro.entity.SysUser;
import com.zhou.common.mybatis.template.shiro.utils.ShiroUtils;
import com.zhou.common.operator.log.core.model.PrincipalInfo;
import com.zhou.common.operator.log.core.resolver.AbstractHttpServletRequestPrincipalResolver;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class ShiroPrincipalResolver extends AbstractHttpServletRequestPrincipalResolver {

    @Override
    protected PrincipalInfo resolveWithRequest(HttpServletRequest request) {
        SysUser sysUser = ShiroUtils.getSysUser();

        PrincipalInfo principalInfo = new PrincipalInfo();
        principalInfo.setUserId(sysUser.getId() + "");
        principalInfo.setUserName(sysUser.getLoginName());
        principalInfo.setUserPhone(sysUser.getPhonenumber());
        principalInfo.setOrgId(sysUser.getDeptId() + "");
        return principalInfo;
    }


}